/*
https://leetcode-cn.com/problems/total-hamming-distance/solution/yi-ming-ju-chi-zong-he-by-leetcode-solut-t0ev/
 */
public class Solution477 {
    public int totalHammingDistance(int[] nums) {
        int ans=0;
        for (int i=0;i<30;i++){
            int count1=0,count2=0;
            for (int num : nums) {
                if ((num&(1<<i))!=0){
                    count1++;
                }else{
                    count2++;
                }
            }
            ans=ans+count1*count2;
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution477().totalHammingDistance(new int[]{4,14,2}));
    }
}
